package service;

import dao.BookList;
import view.BookMenuView;


import java.util.Scanner;

/**
 * @Description 借书方法
 * @Author hhy
 * @Date 2020/9/17 11:25
 */
public class BorrowBookService {
    BookList bookList = BookList.getInstance();
    public void borrow(){
        Scanner sc = new Scanner(System.in);
        String next = "";
        System.out.println("下面是书店有的书，你可以借有库存的书");
        System.out.println("你想借哪本书呢(输入序号)");
        //先查看输入列表
        System.out.println("序号\t\t\t书名\t\t库存");
        bookList.getBookList();
        int bookId = sc.nextInt();
        if(bookId==5) {
            new BookMenuView().view();
            return;
        }
        //借书，如果成功的话，库存是减一的
        String borrowBook = bookList.borrow(bookId);

        if (borrowBook.equals("借书失败")){
            System.out.println("这本书暂时没有库存了试试别的书吧QAQ");
            next = "y";
        }else {
            bookList.myBorrowBook(bookId);
            System.out.println("借书成功了！");
            System.out.println(borrowBook+"到手了，是否还要继续借书呢（y/n）");
            next = sc.next();
        }
        if (!next.equals("y")){
            new BookMenuView().view();
            return;
        }

        borrow();

    }
}
